package com.sxz.sbs.module.client.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.client.bean.ClientListBean;
import com.sxz.sbs.module.client.view.ClientListView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;

/**
 * 获取客户列表管理
 */
public class ClientListPresenter extends RxPresenter<ClientListView>{
    /**
     * @param map
     */
    public void getClientList (final HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getClientList(map)
                .compose(RxUtil.<ClientListBean>handleResult())
                .subscribeWith(new RxSubscriber<ClientListBean>(mView){
                    @Override
                    public void onNext(ClientListBean data) {
                       mView.onClientListSuccess(data);
                    }
                })
        );
    }
    /**
     * 新增通话记录
     * @param map
     */
    public void addCallRecord (final HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().addCallRecord(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView){
                    @Override
                    public void onNext(String data) {
                        mView.onAddCallRecordSuccess();
                    }
                })
        );
    }
    /**
     * 添加意向客户
     * @param map
     */
    public void getAddIntentionClient (final HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getAddIntentionClient(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView,true){
                    @Override
                    public void onNext(String data) {
                        mView.onAddIntentionClientSuccess();
                    }
                })
        );
    }
}
